function [ new_cap_tree_num, new_cap_starts, new_cap_ends, new_cap_rads ] = pluscap( cap_trees)
%PLUSCAP Summary of this function goes here
%Detailed explanation goes here
cap_tree_num=[];
cap_starts=[];
cap_ends=[];
cap_rads=[];

for i=1:length(cap_trees)
    if(cap_trees(i).segments_num>2)
        for j=1:cap_trees(i).segments_num
            cap_tree_num=[cap_tree_num;i];
            cap_starts=[cap_starts;cap_trees(i).segments(j).start];
            cap_ends=[cap_ends;cap_trees(i).segments(j).end];
            cap_rads=[cap_rads;cap_trees(i).segments(j).rad];
        end
    end
end

new_cap_tree_num=[];
new_cap_starts=[];
new_cap_ends=[];
new_cap_rads=[];

for i=1:length(cap_trees)
    if(cap_trees(i).segments_num>2)
        for j=1:cap_trees(i).segments_num
            new_cap_tree_num=[new_cap_tree_num;i];
            new_cap_starts=[new_cap_starts;cap_trees(i).segments(j).start];
            new_cap_ends=[new_cap_ends;cap_trees(i).segments(j).end];
            new_cap_rads=[new_cap_rads;cap_trees(i).segments(j).rad];
        end
        tempindex=[];
        distanceofstarts=(cap_trees(i).segments(1).start(1)-cap_starts(:,1)).^2+(cap_trees(i).segments(1).start(2)-cap_starts(:,2)).^2+(cap_trees(i).segments(1).start(3)-cap_starts(:,3)).^2;
        tempindex=find(distanceofstarts<1e-3);
        if(length(tempindex)==1)
            new_cap_tree_num=[new_cap_tree_num;i];
            new_cap_starts=[new_cap_starts;cap_trees(i).segments(1).start];
            new_cap_ends=[new_cap_ends;cap_trees(i).segments(1).end];
            new_cap_rads=[new_cap_rads;cap_trees(i).segments(1).rad];
        end
    end
end
end

